package com.example.controller;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.example.model.TestModel;
import com.example.model.request.User;
import com.example.service.TestService;

@Controller
public class TestController {
	
	private static Logger log = Logger.getLogger(TestController.class);
	
	@Autowired
	private TestService testService;
	
	/**
	 * Test hello
	 * @return
	 */
	@RequestMapping("/hello")
	@ResponseBody
	public String sayHello() {
		
		String infos =testService.getTestInfo();
		return infos;	
	}
	
	/**
	 * Begin
	 * @param json
	 * @return
	 */
	@RequestMapping("/")
	public @ResponseBody String listAll(@RequestBody JSONObject json) {
		System.out.println("############### Infos:" + json.getString("name"));
		System.out.println("############### Age:" + json.getInteger("Age"));
		log.info("$$$$$$$$$$$$$ Infos:" + JSONObject.toJSONString(json));
		List<TestModel> infos = testService.listAll();
		return JSONObject.toJSONString(infos);
	}
	
	/**
	 * Do Test
	 * @param user
	 * @return
	 */
	@RequestMapping("/1")
	public @ResponseBody List<TestModel> listAll1(@RequestBody User user) {
		log.info("Users:" + JSONObject.toJSONString(user));
		List<TestModel> infos = testService.listAll();
		return infos;
	}
	
}
